<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鼠标随div移动</title>
    <style type="text/css">
        #box1{
            width: 100px;
            height: 100px;
            background-color: deepskyblue;
            position: absolute;
        }
    </style>
    <script type="text/javascript">
    window.onload = function () {
        var box1 = document.getElementById('box1');

        document.onmousemove = function (event) {

            event = event || window.event;

            var st = document.body.scrollTop || document.documentElement.scrollTop;
            var sl = document.body.scrollLeft || document.documentElement.scrollLeft;

            console.log(st);

            var x = event.clientX;
            var y = event.clientY;

            box1.style.left = x +sl+'px';
            box1.style.top = y +st+'px';


        }
    }
    </script>
</head>
<body style="height: 1000px">
    <div id="box1"></div>
</body>
</html>